package com.example.myproviderapp;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ScrollView;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    private Button btselect;
    private DBOpenHelper myhelper;
    private Context mcontext;
    private StringBuilder sb;
    private ScrollView scrollView;
    private TextView txt;
    private SQLiteDatabase db;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mcontext=MainActivity.this;
        myhelper =new DBOpenHelper(mcontext,"song_db",null,1);
        scrollView =(ScrollView)findViewById(R.id.scrollView1);
        txt=(TextView)findViewById(R.id.textView1);
        btselect=(Button) findViewById(R.id.button);
        btselect.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                db=myhelper.getWritableDatabase();
                sb=new StringBuilder();
                Cursor cursor=db.query("test",null,null,null,null,null,null);
                while(cursor.moveToNext())
                {
                    @SuppressLint("RANGE") Integer id=cursor.getInt(cursor.getColumnIndex("_id"));
                    @SuppressLint("RANGE") String name=cursor.getString(cursor.getColumnIndex("name"));
                    sb.append("ID:     "+id+"     "+"NAME:     "+name+"\n");
                }
                sb.toString();
                txt.setText(sb);
                System.out.println(sb);
            }
        });
    }


}